package com.lfp.socketio.listener;

import com.corundumstudio.socketio.AuthorizationListener;
import com.corundumstudio.socketio.HandshakeData;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.listener.ConnectListener;
import com.corundumstudio.socketio.listener.DisconnectListener;
import com.lfp.socketio.SocketIoHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lfp
 */
@Component
public class SocketIoListener implements AuthorizationListener, ConnectListener, DisconnectListener {

   @Autowired
   public SocketIoHolder socketIoHolder;

   @Override
   public void onConnect(SocketIOClient client) {
      socketIoHolder.add(client);
   }

   @Override
   public void onDisconnect(SocketIOClient client) {
      socketIoHolder.remove(client);
   }

   @Override
   public boolean isAuthorized(HandshakeData handshakeData) {
      return true;
   }
}
